package com.igeek.oa.controller;

import com.igeek.oa.entity.OfficesuppliesApply;
import com.igeek.oa.entity.Offsupapply;
import com.igeek.oa.result.Result;
import com.igeek.oa.service.IOfficesuppliesApplyService;
import com.igeek.oa.service.IOffsupapplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/offsupapply")
@Api("办公用品申请")
public class OffsupapplyController {
    @Autowired
    private IOffsupapplyService iOffsupapplyService;
    @Autowired
    private IOfficesuppliesApplyService iOfficesuppliesApplyService;
    @ApiOperation("添加办公用品申请表单")
    @PostMapping("/addOfficesupply/{eId}")
    public void addOfficesupply(@ApiParam("员工编号") @PathVariable("eId") String eId,
                                @ApiParam("申请表信息集合") @RequestBody List<OfficesuppliesApply> newGoods){
        Offsupapply offsupapply = iOffsupapplyService.addOffsupapply(eId);
        System.out.println("拿到的随机数"+offsupapply.getaId()+"-----------------------");
        iOfficesuppliesApplyService.addOfficesuppliesApply(newGoods,offsupapply.getaId());
    }
    @ApiOperation("上传文件并邮箱发送")
    @PostMapping("/getFile/{email}")
    public Result getFile(@PathVariable("email") String email,
                          @RequestParam("file") MultipartFile file){
       return  iOffsupapplyService.sendFile(email,file);
    }
    @ApiOperation("上传文件返回给前端页面")
    @PostMapping("/getExcel")
    public Result getExcel(@RequestParam("file") MultipartFile file) {
        return iOffsupapplyService.getExcel(file);
    }



}
